package com.ycf.demo1;

import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.ycf.demo1.service.Register;

public class RegisterActivity extends AppCompatActivity {
    String username, password, qq;
    String info = "";

    @Override
    public void onCreate(Bundle savedInstanceStat) {

        super.onCreate(savedInstanceStat);
        setContentView(R.layout.activity_register);
    }

    public void registered(View view) {
        username = ((EditText) findViewById(R.id.usernameEdit)).getText().toString();
        password = ((EditText) findViewById(R.id.passwordEdit)).getText().toString();
        qq = ((EditText) findViewById(R.id.qqEdit)).getText().toString();
        new Thread(){
            @Override
            public void run() {
                try {
                    Looper.prepare();
                    info = new Register().userRegister(username, password, qq);
                    System.out.println("info1 = " + info);
                    Toast.makeText(RegisterActivity.this, info, Toast.LENGTH_LONG).show();

                    sleep(1500);
                    if ("注册成功,请登录".equals(info)){
                        Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
                        startActivity(intent);
                    }
                    Looper.loop();//增加部分
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();

    }
}
